﻿using System;
using System.Windows;

namespace muyu_monitor_plugin
{
    public partial class MuyuLogWindow : Window
    {
        private MuyuMonitor mMuyuMonitor;

        //public delegate void RenderedCallback();

        public Action mRenderedCallback;

        //private MuyuLogWindowContentRenderedCallbck mRenderedCallbck;

        public MuyuLogWindow(MuyuMonitor muyuMonitor)
        {
            InitializeComponent();
            // 初始化MuyuLogger
            ContentRendered += MainWindow_ContentRendered;
            mMuyuMonitor = muyuMonitor;
        }

        
        private void MainWindow_ContentRendered(object sender, EventArgs e)
        {
            // ContentRendered事件处理程序
            Console.WriteLine("窗口已经显示出来了！");
            //mRenderedCallbck?.OnRendered();
            mRenderedCallback?.Invoke();
        }

        public void SetContentRenderedCallback(Action renderedCallbck)
        {
            mRenderedCallback = renderedCallbck;
        }

        // 当添加新日志时调用的UpdateLog方法
        public void UpdateLog(string log)
        {
            // 将新日志追加到Label中并换行
            logLabel.Text += log + "\n";
            ScrollToBottom();
        }

        private void ScrollToBottom()
        {
            // 将滚动条滚动到底部
            scrollViewer.ScrollToEnd();
        }

        private void QiaoMuyu_Button_Click(object sender, RoutedEventArgs e)
        {
            mMuyuMonitor.QiaoMuyuOnce();
        }

        private void ClearLog_Button_Click(object sender, RoutedEventArgs e)
        {
            // 清除日志按钮的点击事件处理逻辑
            logLabel.Text = string.Empty;
        }

    }
}
